package com.study.jdbc.factory;

import java.util.ResourceBundle;

import com.study.jdbc.crud.ItemCRUD;

/**
* @Name: BeanFactory
* @Description: Bean对象工厂类
* @Author: 李超	lc_jack@foxmail.com
* @CreateDate: 2017-2-16 下午4:23:43 
* @Version: V1.0
 */
public class BeanFactory {
	
	private static BeanFactory beanFactory = null ;
	
	private BeanFactory() {}
	
	public static BeanFactory getInstance() {
		if(beanFactory != null) {
			return beanFactory ;
		}
		return new BeanFactory() ;
	}
	
	public ItemCRUD getItemCRUDImpl() {
		ResourceBundle bundle = ResourceBundle.getBundle("com/study/jdbc/beans") ;
		String itemCRUDImplName = bundle.getString("ItemCRUDImpl") ;
		ItemCRUD itemCRUD = null ;
		try {
			itemCRUD = (ItemCRUD) Class.forName(itemCRUDImplName).newInstance() ;
		} catch (InstantiationException | IllegalAccessException
				| ClassNotFoundException e) {
			System.out.println("创建ItemCRUD接口实现实例失败！");
			e.printStackTrace();
		}
		return itemCRUD ;
	}

}












